package com.lipaluma.context;

import java.util.HashMap;
import java.util.Map;

import com.lipaluma.context.mapping.AnnotationMappingManager;
import com.lipaluma.context.mapping.BasicMappingManager;
import com.lipaluma.context.mapping.MappingManager;
import com.lipaluma.context.mapping.XmlMappingManager;

public class Context {
	private MappingManager mappingManager;
	private Map<String, Object> optionParameters = new HashMap<String, Object>();
	
	public Context(MappingManager mappingManager) {
		this.mappingManager = mappingManager;
	}
	
	public MappingManager getMappingManager() {
		return mappingManager;
	}
	public boolean isMappedByAnnotation(){
		return AnnotationMappingManager.class.isAssignableFrom(mappingManager.getClass());
	}
	public AnnotationMappingManager getMappingManagerByAnnotation() {
		return (AnnotationMappingManager)mappingManager;
	}
	public BasicMappingManager getBasicMappingManager() {
		return (BasicMappingManager)mappingManager;
	}
	public XmlMappingManager getMappingManagerByXml() {
		return (XmlMappingManager)mappingManager;
	}
	public <MANAGER extends MappingManager> MANAGER getMappingManagerAs(Class<MANAGER> managerClass) {
		return managerClass.cast(mappingManager);
	}
	
	public void addNewOptionParameter(String key, Object parameter) {
		optionParameters.put(key, parameter);
	}
	
	public Object getOptionParameter(String key) {
		return optionParameters.get(key);
	}
}
